Ext.define('component.customer.cusInfoPanel', {
	extend : 'Ext.form.Panel',
	initComponent:function(){
	 var custemInfo = Ext.create('Ext.form.FormPanel',{
//		   frame: true,
//		   minHeight:170,
		   collapsible: true,  //可折叠
	       autoScroll:false,
	       defaults: {
		    	 anchor: '100%',
		    },
		    fieldDefaults: {
		        margin: 2
		    },
	       title:'客户购房需求',
			xtype : "container",
			layout : "hbox",
	       items: [{
	            items: [{
		            xtype:'displayfield',  
		            fieldLabel:'置业动机',  
		            minWidth:600,
	    			name:'dongjiName'
	            }, {
		            xtype:'displayfield',  
		            fieldLabel:'需求面积',  
		            minWidth:600,
	    			name:'mianji'
	            }, {
		            xtype:'displayfield',  
		            fieldLabel:'生活服务',  
		            minWidth:600,
	    			name:'shenghuo'
	            }, {
		            xtype:'displayfield',  
		            fieldLabel:'预算总价',  
		            minWidth:600,
	    			name:'zongjia'
	            },{
		            xtype:'displayfield',  
		            fieldLabel:'希望庭院具备功能',  
		            minWidth:600,
	    			name:'gongneng'
	            },{
	            	xtype:'displayfield',  
		            fieldLabel:'付款方式',  
	    			name:'rqPaymentMethod'
	            },{
	            	xtype:'displayfield',  
		            fieldLabel:'意向物业类型',  
	    			name:'yixiangwuyeType'
	            	
	            },{
	            	xtype:'displayfield',  
		            fieldLabel:'购买车位',  
	    			name:'buyCar'
	            	
	            }]
	        }, {
	            items: [{
		            xtype:'displayfield',  
		            fieldLabel:'关注重点',  
		            minWidth:600,
	    			name:'zhongdianName'
	            },{
		            xtype:'displayfield',  
		            fieldLabel:'需求楼层',  
		            minWidth:600,
	    			name:'louceng'
	            },{
		            xtype:'displayfield',  
		            fieldLabel:'生活配套',  
		            minWidth:600,
	    			name:'peitao'
	            },{
		            xtype:'displayfield',  
		            fieldLabel:'预算单价',  
		            minWidth:600,
	    			name:'danjia'
	            },{
	                xtype:'displayfield',
	                fieldLabel: '庭院需求面积',
		            minWidth:600,
	                name: 'rqCourtyardArea',
	                id:'rqCourtyardArea'
	            },{
	            	xtype:'displayfield',
		            fieldLabel: '家庭结构',
		            name: 'familyJie'
	            },{
	            	xtype:'displayfield',
		            fieldLabel: '需求户型规格',
		            name: 'xuqiuhuxingType'
		            
	            	
	            }]
	        }]
		   
	   });
	 var custemInfo1 = Ext.create('Ext.form.FormPanel',{
//		   frame: true,
//		   minHeight:170,
		   collapsible: true,  //可折叠
	       autoScroll:false,
	       defaults: {
		    	 anchor: '100%',
		    },
		    fieldDefaults: {
		        margin: 2
		    },
	       title:'首次接触信息',
			layout: 'hbox',
			items: [{
	            items: [{
		            xtype:'displayfield',  
		            fieldLabel:'接触方式',
		            minWidth:600,
	    			name:'jiechuType'
	            }, {
	                xtype:'displayfield',
	                fieldLabel: '接触时间',
		            minWidth:600,
	                name: 'ftContactTimes',
	                id:'ftContactTimes'
	            }, {
	                xtype:'displayfield',
	                fieldLabel: '沟通内容',
		            maxWidth:600,
	                name:'ftContactContent'
	            }]
	        }]
		   
	   });
/*	   custemInfo1.getForm().load({
			url:jypath+'/customer/customer/findCustomerInfo',
			params:{'customerId':customerId},
			success:function(form, action){
				var obj = action.result.data;
				custemInfo1.getForm().findField("ftContactTimes").setValue(Ext.Date.format(new Date(obj.ftContactTime),'Y-m-d'));
				custemInfo.getForm().setValues(obj);
			},   
			failure: function(form, action) {
		        Ext.Msg.alert("加载失败", action.result.errorMessage);
		    }

		});*/

	 var c1 = Ext.create('Ext.form.FormPanel',{
//		   frame: true,
//		   minHeight:170,
		   collapsible: true,  //可折叠
	       autoScroll:false,
	       defaults: {
		    	 anchor: '100%',
		    },
		    fieldDefaults: {
		        margin: 2
		    },
	       title:'客户个人信息',
	       layout: 'hbox',
			items: [{
	            items: [{
		            xtype:'displayfield',  
		            fieldLabel:'证件类型',
		            minWidth:600,
	    			name:'zhengjianType'
	            }, {
	                xtype:'displayfield',
	                fieldLabel: '证件号码',
		            minWidth:600,
	                name: 'peDocumentNumber'
	            }, {
	                xtype:'displayfield',
	                fieldLabel: '出生日期',
		            minWidth:600,
	                name: 'peBirth'
	            }, {
	                xtype:'displayfield',
	                fieldLabel: '年龄',
		            minWidth:600,
	                name: 'peAge'
	            }, {
	                xtype:'displayfield',
	                fieldLabel: '固定电话',
		            minWidth:600,
	                name: 'peTelephone'
	            }, {
	                xtype:'displayfield',
	                fieldLabel: '邮箱',
		            minWidth:600,
	                name: 'peEmail'
	            }, {
	                xtype:'displayfield',
	                fieldLabel: '微信',
		            minWidth:600,
	                name: 'peWechat'
	            }, {
		            xtype:'displayfield',  
		            fieldLabel:'车驾品牌',
		            minWidth:600,
	    			name:'pinpai'
	            }, {
		            xtype:'displayfield',  
		            fieldLabel:'乐于参加的活动类型',
		            minWidth:600,
	    			name:'huodongType'
	            },{
	            	 xtype:'displayfield',
		             fieldLabel: '邮编',
		             name: 'pePostcode',
					 renderer:function(val){
                        if(val && 'null' == val){
                            return "";
                        }else{
                            return val;
                        }
                     }
	            },{
	            	 xtype:'displayfield',
		             fieldLabel: '学历',
		             name: 'peAcademicQualifications'
	            },{
	            	 xtype:'displayfield',
		             fieldLabel: '从事行业',
		             name: 'congshihangye'
		           
	            },{
	            	 xtype:'displayfield',
		             fieldLabel: '公司性质',
		             name: 'companyXingzhi'
		            
	            },{
	            	xtype:'displayfield',
		             fieldLabel: '公司年营业额',
		             name: 'companyYingye'
	            	
	            },{
	            	 xtype:'displayfield',
		             fieldLabel: '是否员工',
		             name: 'isYuangong',
		             renderer:function(val){
		            	 if(val!=""&&val!=null){
		            		 if(val=="1"){
		            			 return "是";
		            		 }else if(val=="0"){
		            			 return "否";
		            		 }
		            	 }else{
		            		 return "";
		            	 }
		             }
		             
	            }]
	        }, {
	            items: [{
		            xtype:'displayfield',  
		            fieldLabel:'户籍所在地',
		            minWidth:600,
	    			name:'huji'
	            }, {
	                xtype:'displayfield',
	                fieldLabel: '联系地址',
		            minWidth:600,
	                name: 'peContactAddress'
	            }, {
	            	items: [{
			            xtype:'displayfield',  
			            fieldLabel:'居住地',
		    			name:'jusheng',
		    			id:'jusheng',
			            minWidth:600
		            }/*,{
			            xtype:'displayfield',  
			            fieldLabel:'居住市',
		    			name:'jucity',
			            minWidth:600
		            },{
			            xtype:'displayfield',  
			            fieldLabel:'居住区',
			            minWidth:600,
		    			name:'juarea'
		            }*/]
	            }, {
	                xtype:'displayfield',
	                fieldLabel: '小区',
		            minWidth:600,
	                name: 'pePlot'
	            }, {
	                xtype:'displayfield',
	                fieldLabel: '详细地址',
		            minWidth:600,
	                name: 'peDetailedAddress'
	            }, {
	            	items: [{
			            xtype:'displayfield',  
			            fieldLabel:'工作地',
			            minWidth:600,
		    			name:'gongsheng',
		    			id:'gongsheng'
		            }/*,{
			            xtype:'displayfield',  
			            fieldLabel:'工作市',
			            minWidth:600,
		    			name:'gongcity'
		            },{
			            xtype:'displayfield',  
			            fieldLabel:'工作区',
			            minWidth:600,
		    			name:'gongarea'
		            }*/]
	            }, {
	                xtype:'displayfield',
	                fieldLabel: '详细地址',
		            minWidth:600,
	                name: 'peWorkaroundAddress'
	            }, {
		            xtype:'displayfield',  
		            fieldLabel:'家庭年收入',
		            minWidth:600,
	    			name:'shouru'
	            }, {
		            xtype:'displayfield',  
		            fieldLabel:'兴趣爱好',
		            minWidth:600,
	    			name:'aihao'
		            
	            },{
	            	 xtype:'displayfield',
		             fieldLabel: '是否有子女',
		             name: 'isZinv',
		             renderer:function(val){
		            	 if(val!=""&&val!=null){
		            		 if(val=="1"){
		            			 return "是";
		            		 }else if(val=="0"){
		            			 return "否";
		            		 }
		            	 }else{
		            		 return "";
		            	 }
		             }
		            
            },{
            	 xtype:'displayfield',  
		         fieldLabel:'是否与老人同住',  
	    		 name:'isLaoren',
	    		 renderer:function(val){
	            	 if(val!=""&&val!=null){
	            		 if(val=="1"){
	            			 return "是";
	            		 }else if(val=="0"){
	            			 return "否";
	            		 }
	            	 }else{
	            		 return "";
	            	 }
	             }
	    		
            },{
		            	 xtype:'displayfield',
			             fieldLabel: 'QQ号码',
			             name: 'qqNumber'
	            },{
	            	 xtype:'displayfield',  
			         fieldLabel:'是否本公司业主',  
		    		 name:'isYezhu'
//		    			 ,
//		    		 renderer:function(val){
//		            	 if(val!=""&&val!=null){
//		            		 if(val=="1"){
//		            			 return "是";
//		            		 }else if(val=="0"){
//		            			 return "否";
//		            		 }
//		            	 }else{
//		            		 return "";
//		            	 }
//		             }
		    		
	            },{
	            	 xtype:'displayfield',  
			         fieldLabel:'日常信息获取途径',  
		    		 name:'richangxinxi'
	            }]
	        }]
		   
	   });


	 
	 var gridStoreg = Ext.create('Ext.data.Store', {
	        fields: ["id","memberName","documentType", "documentNumber"
	                 , "birthday","marryday","mobile","relationship"],
	        //pageSize: 10,  //页容量5条数据
	        //是否在服务端排序 （true的话，在客户端就不能排序）
	        remoteSort: false,
	        proxy: {
	            type: 'ajax',
	            url: contextPath+'/customer/familyMember/findList',
	            //url: jypath+'/customer/customer/familyMemberList',
	            actionMethods: { read: 'POST' },
	            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
	                type: 'json', //返回数据类型为json格式
	                root: 'obj',  //数据
	                totalProperty: 'total' //数据总条数
	            }
	        },
	        autoLoad: false  //即时加载数据
	    });
		
		gridStoreg.on("beforeload",function(){
	        Ext.apply(gridStoreg.proxy.extraParams,{customerId:customerId,memberType:'1'});
	    });
		
		var documentTypeStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "codeName"],
	        proxy:{
	            type:'ajax',
	            url:contextPath+'/system/baseCodeValue/getCodeValueByType?typeId=12',
	            reader:{
					type: 'json',
					root: 'root'  //数据
			   }
	        },
	        autoLoad:false
		});
		
		documentTypeStore.load({
			callback:function(){
				gridStoreg.load();
			}
		});

        var relationshipList = [
            {"value":"1", "text":"父亲"},
            {"value":"2", "text":"母亲"},
            {"value":"3", "text":"丈夫"},
            {"value":"4", "text":"妻子"},
            {"value":"5", "text":"儿子"},
            {"value":"6", "text":"女儿"},
            {"value":"7", "text":"实际购房者"},
            {"value":"99", "text":"其他"}
        ];

        relationshipStore = new Ext.data.Store({
            autoDestroy: true,
            fields :["value","text"],
            data : relationshipList
        });
		
		var gridg = Ext.create('Ext.grid.Panel', {
			minHeight:200,
	        store: gridStoreg,
	        columnLines: true,
	        columns: [{
                text     : '客户名称',
                dataIndex: 'memberName'
            },{
                text     : '手机号',
                dataIndex: 'mobile'
            },{
                text     : '成员关系',
                dataIndex: 'relationship',
                renderer : function(value) {
                    if(value){
                        var index = relationshipStore.find('value',value);
                        if(index!=-1){
                            return relationshipStore.getAt(index).data.text;
                        }
                        return value;
                    }
                }
            },{
	            text     : '证件类型',
	            dataIndex: 'documentType',
	            renderer : function(value) {
	            	if(value){
	            		var index = documentTypeStore.find('id',value);
	                    if(index!=-1){  
	                        return documentTypeStore.getAt(index).data.codeName;  
	                    }  
	                    return value;
	            	}
	            }
	        },{
	            text     : '证件号码',
	            dataIndex: 'documentNumber'
	        },{
	            text: '生日',
	            dataIndex: 'birthday',
	            renderer:function(value){
	            	if(value){
	            		return Ext.Date.format(new Date(value),'Y-m-d');
	            	}
	            }
	        },{
	            text: '结婚纪念日',
	            dataIndex: 'marryday',
	            renderer:function(value){
	            	if(value){
	            		return Ext.Date.format(new Date(value),'Y-m-d');
	            	}
	            }
	        }
	        ],
	        title: '家庭成员',
	        dockedItems: [{  
	            xtype: 'pagingtoolbar',  
	            store: gridStoreg,   // GridPanel中使用的数据  
	            dock: 'bottom',  
	            displayInfo: true,  
	            emptyMsg:"没有数据",  
	            displayMsg:"显示从{0}条数据到{1}条数据，共{2}条数据"
	        }
	        ]
	    });
	 
	 var c2 = Ext.create('Ext.form.FormPanel',{
//		   frame: true,
//		   minHeight:170,
		   collapsible: true,  //可折叠
	       autoScroll:false,
	       defaults: {
		    	 anchor: '100%',
		    },
		    fieldDefaults: {
		        margin: 2
		    },
	       title:'家庭住宅情况',
			layout: 'hbox',
			items: [{
	            items: [{
	                xtype:'displayfield',
	                fieldLabel: '本地购买房数',
		            minWidth:600,
	                name: 'reLocalPurchase'
	            }, {
            		xtype:'displayfield',
	                fieldLabel:'目前家庭持有住宅数',
		            minWidth:600,
	                name:'reCurrentHoldings'
	            }, {
		            xtype:'displayfield',  
		            fieldLabel:'目前居住的面积',
		            minWidth:600,
	    			name:'jumian'
	            }, {
		            xtype:'displayfield',  
		            fieldLabel:'目前居住/办公的房子属性',
		            minWidth:600,
	    			name:'jushu'
	            }]
	        }, {
	            items: [{
	                xtype:'displayfield',
	                fieldLabel: '目前家庭住宅已按揭数',
		            minWidth:600,
	                name: 'reResidentialMortgage'
	            },{
		            xtype:'displayfield',  
		            fieldLabel:'目前居住的物业类型',
		            minWidth:600,
	    			name:'juType'
	            },{
		            xtype:'displayfield',  
		            fieldLabel:'目前居住的户型结构',
		            minWidth:600,
	    			name:'jujie'
	            }]
	        }]
		   
	   });
	 var c3 = Ext.create('Ext.form.FormPanel',{
//		   frame: true,
//		   minHeight:170,
		   collapsible: true,  //可折叠
	       autoScroll:false,
	       defaults: {
		    	 anchor: '100%',
		    },
		    fieldDefaults: {
		        margin: 2
		    },
	       title:'联系信息',
			layout: 'hbox',
			items: [{
	            items: [{
		            xtype:'displayfield',  
		            fieldLabel:'工作日联系时间',
		            minWidth:600,
	    			name:'gonglian'
	            }, {
		            xtype:'displayfield',  
		            fieldLabel:'工作日联系方式',
		            minWidth:600,
	    			name:'gongType'
	            }, {
	                xtype:'displayfield',
	                fieldLabel: '备注',
		            maxWidth:600,
	                name:'remark'
	            }]
	        }, {
	            items: [{
		            xtype:'displayfield',  
		            fieldLabel:'周末联系时间',
		            minWidth:600,
	    			name:'freelian'
	            },{
		            xtype:'displayfield',  
		            fieldLabel:'周末联系方式',
		            minWidth:600,
	    			name:'freeType'
	            }]
	        }]
		   
	   });
	 
	   c1.getForm().load({
			url:jypath+'/customer/customer/findCustomerInfo',
			params:{'customerId':customerId},
			success:function(form, action){
				var obj = action.result.data;
                var juStr=String(obj.jusheng != null ? obj.jusheng : '')+String(obj.jucity!= null ?obj.jucity : '')+String(obj.juarea != null ? obj.juarea.toString() : '');
                var gongStr=String(obj.gongsheng==null?'':obj.gongsheng)+String(obj.gongcity==null?'':obj.gongcity)+String(obj.gongarea==null?'':obj.gongarea);

				if(obj.rqCourtyardArea)
				Ext.getCmp("rqCourtyardArea").setValue(obj.rqCourtyardArea+"㎡");
				Ext.getCmp("jusheng").setValue(juStr);
				Ext.getCmp("gongsheng").setValue(gongStr);
				custemInfo.getForm().setValues(obj);
				custemInfo1.getForm().setValues(obj);
				c2.getForm().setValues(obj);
				c3.getForm().setValues(obj);
				if(obj.ftContactTime!=""&&obj.ftContactTime!=null){
					custemInfo1.getForm().findField("ftContactTimes").setValue(Ext.Date.format(new Date(obj.ftContactTime),'Y-m-d'));
				}else{
					custemInfo1.getForm().findField("ftContactTimes").setValue("");
				}
				
				
			},   
			failure: function(form, action) {
		        Ext.Msg.alert("加载失败", action.result.errorMessage);
		    }

		});
		
		var defaultConfig = {
				defaults: {  
		            split: true,    //有分割线  
		            collapsible: true,  //可以折叠
		        },
				items:[custemInfo,custemInfo1,c1,gridg,c2,c3]
		};
		Ext.apply(this,defaultConfig);
		this.callParent(arguments);
		
	}
});
